package com.ponhu.ea2.stockcenter.provider.service.biz;

import com.ponhu.ea2.stockcenter.provider.constants.CommonConstant;
import org.springframework.stereotype.Service;

/**
 * 计算库存数据服务
 *
 * @author Wang
 * @date 2021/11/6 3:51 下午
 */
@Service
public class CalcStockDataService {

    /**
     * @param origin            原始库存数
     * @param inventoryQuantity 需要增加/减少个数
     * @param StockActionCode   库存动作类型
     * @return
     */
    public static Integer getOperatorResult(Integer origin, Integer inventoryQuantity, Integer StockActionCode) {

        if (!(StockActionCode == CommonConstant.STOCK_ACTION_RESPONSE.PLUS ||
                StockActionCode == CommonConstant.STOCK_ACTION_RESPONSE.SUBTRACT ||
                StockActionCode == CommonConstant.STOCK_ACTION_RESPONSE.REAL_PLUS_AND_UNREAL_SUBTRACT ||
                StockActionCode == CommonConstant.STOCK_ACTION_RESPONSE.REAL_SUBTRACT_AND_UNREAL_PLUS)) {
            return origin;
        }

        return (StockActionCode == CommonConstant.STOCK_ACTION_RESPONSE.PLUS ||
                StockActionCode == CommonConstant.STOCK_ACTION_RESPONSE.REAL_PLUS_AND_UNREAL_SUBTRACT)
                ? (origin + Math.abs(inventoryQuantity)) :
                (origin - Math.abs(inventoryQuantity));
    }

}
